package com.lehuowujie.lehuomarket.ui;

import android.view.LayoutInflater;
import android.widget.TextView;
import android.widget.Toast;

import com.lehuowujie.lehuomarket.R;
import com.lehuowujie.lehuomarket.base.BaseActivity;
import com.lehuowujie.lehuomarket.flowlayout.FlowLayout;

import java.util.List;

/**
 * Created by 王瑞铭 on 2017/1/17.
 */
public class FlowActivity extends BaseActivity {

    private String[] mVals = new String[]{
            "Hello", "Android World", "TextView", "Button",
            "Hello", "Android", "Text", "Button",
            "Hello Android", "Android", "TextView", "Button",
            "Hello", "Android IOS", "TextView", "Button",
            "Hello", "Android", "TextView", "ButtonImage"
    };

    FlowLayout flowLayout;

    @Override
    public int setContentViewRes() {
        return R.layout.activity_flow;
    }

    @Override
    public void initView() {
        initToolBar();
        setTitle("流式布局");
        setBack(true);
        flowLayout = (FlowLayout) findViewById(R.id.id_flowlayout);
    }

    @Override
    public void initEvent() {
        initData();
        flowLayout.setOnFlowItemClickListener(new FlowLayout.OnFlowItemClickListener() {
            @Override
            public void onFlowItemClick(int currentSelectPosition, List<Integer> selectList) {
                Toast.makeText(FlowActivity.this, currentSelectPosition + "size==" + selectList.size(), Toast.LENGTH_LONG).show();
            }
        });
    }

    private void initData() {
        LayoutInflater mInflater = LayoutInflater.from(this);
        for (int i = 0; i < mVals.length; i++) {
            TextView tv = (TextView) mInflater.inflate(R.layout.tv, flowLayout, false);
            tv.setText(mVals[i]);
            flowLayout.addView(tv);
        }
    }
}
